package org.ceteca.explica.core.partners;

import java.io.Serializable;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.ceteca.explica.core.common.BaseVO;



/**
 * @author Juan C. Díaz (juancarlosdiaz@ceteca.net) <br>
 *         Copyright (c) 2009 Fundación Centro Tecnolóxico da Carne
 * 
 * <br>
 * <br>
 *         This program is free software: you can redistribute it and/or modify
 *         it under the terms of the GNU General Public License as published by
 *         the Free Software Foundation, either version 3 of the License, or (at
 *         your option) any later version. <br/>
 *         This program is distributed in the hope that it will be useful, but
 *         WITHOUT ANY WARRANTY 
 *         <br>without even the implied warranty of
 *         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *         General Public License for more details. <br/>
 *         You should have received a copy of the GNU General Public License
 *         along with this program. If not, see <http://www.gnu.org/licenses/>.
 * 
 */
public class ContactOT extends BaseVO implements Serializable {


	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private long idContact;
	private String name;
	private String position;
	private String phone;
	private String fax;
	private String email;
	private PartnerOT partner;
	private Integer version=new Integer(0);
	
	
	
	
	
	public ContactOT() {
		super();

	}




	
	



	public long getIdContact() {
		return idContact;
	}









	public void setIdContact(long idContact) {
		this.idContact = idContact;
	}









	public String getName() {
		return name;
	}









	public void setName(String name) {
		this.name = name;
	}









	public String getPosition() {
		return position;
	}









	public void setPosition(String position) {
		this.position = position;
	}









	public String getPhone() {
		return phone;
	}









	public void setPhone(String phone) {
		this.phone = phone;
	}









	public String getFax() {
		return fax;
	}









	public void setFax(String fax) {
		this.fax = fax;
	}









	public String getEmail() {
		return email;
	}









	public void setEmail(String email) {
		this.email = email;
	}









	public Integer getVersion() {
		return version;
	}







	   @Override
	    public int hashCode() {
	        final HashCodeBuilder hcb = new HashCodeBuilder();
	        hcb.append(getPartner());
	        hcb.append(getName());
	        hcb.append(getPosition());

	        return hcb.toHashCode();
	    }

	    
	    
	    @Override
	    public boolean equals(Object obj) {
	        boolean isEquals = false;
	        try {
	            final ContactOT other = (ContactOT)obj;
	            final EqualsBuilder eqb = new EqualsBuilder();
	            eqb.append(getName(), other.getName());
	            eqb.append(getPartner(), other.getPartner());
	            eqb.append(getPosition(), other.getPosition());
	            isEquals = eqb.isEquals();

	        } catch (Exception e) {
	            isEquals = false;
	        }

	        return isEquals;
	    }









	




	@Override
	public boolean equals(Long id) {
		return id != null && this.idContact == id.longValue();
	}

	@Override
	public String getEntityId() {

		return InterfacePartners.EXPLICA_ENTITY_CONTACT_ID;
	}

	@Override
	public long getInternalId() {

		return this.idContact;
	}

	@Override
	public String getInternalValue() {
		
		return this.name;
	}









	public void setVersion(Integer version) {
		this.version = version;
	}









	@Override
	public String toString() {
		StringBuffer result = new StringBuffer();
		
		try{
				result.append("\n%%%%%%%%%%%% BEGIN CONTACT DETAIL %%%%%%%%%%%%%%");
				result.append("\nID: ");
				result.append(this.idContact);
				result.append("\nName: ");
				result.append(this.name);
				result.append("\nPosition: ");
				result.append(this.position);
				result.append("\n%%%%%%%%%%%% END  CONTACT DETAIL%%%%%%%%%%%%%%%%");
			}
			catch (Exception ex) {
				System.out.println("Error formatting Contact!");
				ex.printStackTrace();
				return null;
			}
			
			return result.toString();
	}









	public PartnerOT getPartner() {
		return partner;
	}









	public void setPartner(PartnerOT partner) {
		this.partner = partner;
	}

	
	
	
	
	
}
